package com.neusoft.neuiotms.dcam.workflow.repository.impl;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import com.neusoft.bizcore.web.jpa.repository.AbstractRepository;
import com.neusoft.bizcore.web.support.Searchable;
import com.neusoft.neuiotms.dcam.workflow.model.PeifaSL;
import com.neusoft.neuiotms.dcam.workflow.model.QPeifaSL;
import com.neusoft.neuiotms.dcam.workflow.repository.CustomizedPeifaSLRepository;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.jpa.impl.JPAQuery;

public class CustomizedPeifaSLRepositoryImpl extends AbstractRepository implements CustomizedPeifaSLRepository {

    @Override
    public Page<PeifaSL> search(Pageable pageable, Searchable searchable) {
        final QPeifaSL q = QPeifaSL.peifaSL;
        final BooleanBuilder where = this.buildWhere(searchable);
        final JPAQuery<PeifaSL> query = this.query().selectFrom(q);
        query.where(where);
        return super.search(query, pageable);
    }

    @Override
    public List<PeifaSL> search(Searchable searchable) {
        final QPeifaSL q = QPeifaSL.peifaSL;
        final BooleanBuilder where = this.buildWhere(searchable);
        final JPAQuery<PeifaSL> query = this.query().selectFrom(q);
        query.where(where);
        return query.fetch();
    }

    private BooleanBuilder buildWhere(final Searchable searchable) {
        final BooleanBuilder where = new BooleanBuilder();
        final QPeifaSL q = QPeifaSL.peifaSL;
        where.and(super.containsStr(q.workOrderNum, searchable, "workOrderNum"));
        where.and(super.inStrings(q.workOrderNum, searchable, "workOrderNumIn"));
        return where;
    }

    @Override
    protected Class<?> getModelClass() {
        return PeifaSL.class;
    }

}
